# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libid3tag

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.15.1b
pkgrel=1
pkgdesc="Library for id3 tagging (mingw-w64)"
arch=('any')
url="http://www.underbit.com/products/mad/"
license=("GPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-zlib")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
groups=("${MINGW_PACKAGE_PREFIX}")
options=('staticlibs' 'strip' '!makeflags')
source=(#"ftp://ftp.mars.org/pub/mpeg/${_realname}-${pkgver}.tar.gz"
    http://sourceforge.net/projects/mad/files/${_realname}/${pkgver}/${_realname}-${pkgver}.tar.gz
    0001-no-undefined.mingw.patch
    0002-update-ac-and-silent-rules.mingw.patch
    '10_utf16.patch'
    '11_unknown_encoding.patch'
    'CVE-2008-2109.patch'
    'id3tag.pc'
    )
md5sums=('e5808ad997ba32c498803822078748c3'
         'd6e03d565052d2267e382e811304ef87'
         '2daec906976c5316db171cc117fb697d'
         '4f9df4011e6a8c23240fff5de2d05f6e'
         '3ca856b97924d48a0fdfeff0bd83ce7d'
         'c51822ea6301b1ca469975f0c9ee8e34'
         '9ee16beebe53f8b89f27504ea3d37385')

prepare() {
  cd "$srcdir/${_realname}-$pkgver"
  patch -p1 -i ${srcdir}/0001-no-undefined.mingw.patch
  patch -p1 -i ${srcdir}/0002-update-ac-and-silent-rules.mingw.patch
  patch -p1 -i ${srcdir}/10_utf16.patch
  patch -p1 -i ${srcdir}/11_unknown_encoding.patch
  patch -Np0 -i ${srcdir}/CVE-2008-2109.patch
  
  touch NEWS AUTHORS ChangeLog
  rm aclocal.m4
  rm Makefile.in
  autoreconf -fi
}

build() {
  mkdir -p $srcdir/build-${MINGW_CHOST} && cd $srcdir/build-${MINGW_CHOST}
    ../${_realname}-$pkgver/configure \
      --prefix=${MINGW_PREFIX} \
      --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
      --enable-shared
  make
}

package() {
    cd "${srcdir}/build-${MINGW_CHOST}"
    make DESTDIR="$pkgdir" install
    install -D -m644 "${srcdir}/id3tag.pc" "${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/id3tag.pc"
  sed -e "s|/usr|${MINGW_PREFIX}|g" -i "${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/id3tag.pc"
}
